package com.ry.quartz.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ry.quartz.service.QuartzJobService;

@RestController
@RequestMapping("/quartz")
public class QuartzJobController {

	@Autowired
	QuartzJobService quartzJobService;

	@RequestMapping("/addJob")
	public String hello(HttpServletRequest request) {
		quartzJobService.addJob("com.ry.quartz.job.HelloWorldJob", "测试任务", "测试任务组", "0/5 * * * * ?");
		return "";
	}

	@RequestMapping("/editJob")
	public String editJob(HttpServletRequest request, String name, String group, String cron) {
		boolean iden = quartzJobService.modifyJob(name, group, cron);
		return String.valueOf(iden);
	}

	@RequestMapping("/getAllJob")
	public List getAllJob(HttpServletRequest request) {
		List<Map<String, Object>> list = quartzJobService.getAllJob();
		return list;
	}

	@RequestMapping("/pauseJob")
	public String pauseJob(HttpServletRequest request, String name, String group) {
		quartzJobService.pauseJob(name, group);
		return "pauseJob";

	}
	
	@RequestMapping("/resumeJob")
	public String resumeJob(HttpServletRequest request, String name, String group) {
		quartzJobService.resumeJob(name, group);
		return "resumeJob";

	}
	
	@RequestMapping("/deleteJob")
	public String deleteJob(HttpServletRequest request, String name, String group) {
		quartzJobService.deleteJob(name, group);
		return "deleteJob";

	}

}
